<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="shortcut icon" href="__IMG__/favicon.ico" />
	<link rel="bookmark" href="__IMG__/favicon.ico" type="image/x-icon" 　/>
	<title>香港六合彩</title>
	<link rel="stylesheet" type="text/css" href="__CSS__/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="__CSS__/common.css"/>
	<link rel="stylesheet" type="text/css" href="__CSS__/index.css"/>
	<script src="__JS__/mui.min.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" charset="utf-8">
        mui.init();
	</script>
	<style>
		.style_tab tr:nth-child(2n) td{
			border-left: 1px solid #e0dfe3;
		}
		.spring_box3 table{
			border: none;
			width: 100%;
			text-align: center;
		}
		.spring_box3 table th,.spring_box3 table td{
			padding: 5px 0;
		}
		.spring_box3 table input[type=number]{
			width: 80px;
			margin: 0;
			padding: 5px;
			height: 25px;
			background: #e2e2e2;
			border:1px solid #D2D2D2;
			color: #E22C2B;
			text-align: center;
		}
		.spring_box3 .table_box{
			min-height: 300px;
		}
		.spring_box3{
			width: 80%;
			background: #fff;
			position: fixed;
			top: 10%;
			left: 10%;
			z-index: 50;
			display: none;
			box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, .5);
		}
		.table_box{
			overflow: auto;
		}
		.spring_box4{
			width: 100%;
			height: 78px;
			position: fixed;
			bottom: 0;
			left:0;
			z-index: 101;
			background: rgba(0,0,0,.3);
			display: none;
		}


	</style>
</head>
<body>
<header class="mui-bar mui-bar-nav">
	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	<h1 class="mui-title">香港六合彩</h1>
	<a class="mui-pull-right mui-h5 blue box1_a  mg_top5"><i id="balance">{$balance}</i><span class="mui-h2 padding_lr10">...</span>	</a>
</header>
<div class="mui-content">
	<div class="play_top">
		<div class="clearfix">
			<div class="left play_top_left">
				<p class="color_ff">第<span>{$stage_data['stage']}</span>期</p>
			</div>
			<div class="left play_top_right">
				<div class="round_box">
					{foreach $stage_data['number'] as $k=>$v}
					{if $k==6}
					<span style="color: white">+</span><i class="round six_{$v|getColor}">{$v}</i>
					{else/}
					<i class="round six_{$v|getColor}">{$v}</i>
					{/if}
					{/foreach}
				</div>
				<div class="squal_box">
					{foreach $stage_data['detail'] as $k=>$v}
					{if $k==6}
					<span style="color: white">+</span><i>{$v}</i>
					{else}
					<i>{$v}</i>
					{/if}
					{/foreach}
				</div>
			</div>
		</div>
		<div class="clearfix padding_tb10">
			<div class="left play_top_left top2">
				<p class="color_ff">第<span id="next_stage">{$stage_data['stage_next']}</span>期</p>
			</div>
			<div class="left play_top_right clearfix">
				<span class="left color_ff">剩余：</span>
				<div class="colockbox clearfix left" id="demo02">
					<span class="hour">00</span>
					<span class="minute">00</span>
					<span class="second">00</span>
				</div>
				<span class="left color_ff">开奖：</span>
				<div class="colockbox clearfix left" id="demo03">
					<span class="hour">00</span>
					<span class="minute">00</span>
					<span class="second">00</span>
				</div>
			</div>
		</div>
	</div>
	<div class="play_mian">
		<div class="clearfix">
			<div class="left play_left">
				<ul class="play_list">
					{foreach $pan as $k=>$v}
					<li {if $k==0} class="active" {/if}><a href="javascript:void(0);">{$v['name']}</a></li>
					{/foreach}
				</ul>
			</div>
			<div class="left play_right my_td">
				{foreach $odds as $k=>$v}
				<div class="play_div {if $k==0} active {/if}">
					<table border="" cellspacing="" cellpadding="" class="style_tab" >
						{foreach $v['titles'] as $kk=>$vv}
						<tr>
							<th colspan="2">{$vv['type_name']}</th>
						</tr>
						{foreach $vv['type_odd'] as $kkk=>$vvv}
						<tr style="float: left; {if in_array($vv['type'],[20,21,22,23,24,25])}width: 30%{else/} width: 50%{/if}">
							<td style="display: inline-block;width: 100%;border:1px solid #e0dfe3;border-top: none;border-left: none;">
								<i style="font-weight: bold"  class="round six_{$vvv['rule']|getColor}" >{$vvv['rule']}</i>
								<span style="font-weight: bold">{$vvv['rate']|number_format=3}</span>
								<input type="hidden" value="{$vv['type_name']}">
								<input type="hidden" value="{$vv['type']}">
							</td>
						</tr>
						{/foreach}
						{/foreach}
					</table>
				</div>
				{/foreach}
			</div>
		</div>
	</div>
</div>
<div class="aside">
	<a href="{:url('mine/service')}"  class="right sever_box"><img class="width_100 mg_top5" src="__IMG__/icon_service.png" alt="" /></a>
</div>
<div class="footer">
	<!--<h6 class="padding_5">已选：<span id="is_choose">0</span>注</h6>-->
	<div class="clearfix padding_lr10 mg_top5">
		<div class="left mui-col-sm-8">
			<input type="number"  id="money" value="" placeholder="请输入金额" />
			<input type="hidden" name="" id="dateline" value="{$stage_data['dateline']}"  />
			<input type="hidden" name="" id="lottery_time" value="{$stage_data['lottery_time']}"/>
			<input type="hidden" name="" id="cate" value="{$cate}"/>
		</div>
		<div class="right mui-col-sm-4">
			<input type="button" id="ok" value="确定" class="bg_red color_ff mg_top10 box3_a" />
			<input type="reset" id="cz" value="重置"  class="bg_blue color_ff mg_top10"/>
		</div>
	</div>
</div>
<div class="spring_box1">
	<ul>
		<li class="bor_b"><a href="{:url('mine/transaction_record',array('cate'=>$cate))}">投注记录</a></li>
		<li class="bor_b"><a href="{:url('lottery/history',array('cate'=>$cate))}">开奖结果</a></li>
		<li><a href="{:url('web/play_rule_web',array('cate'=>$cate))}">游戏规则</a></li>
	</ul>
</div>
<div class="spring_box3">
	<div class="padding_10">
		<h4 class="blue text-center mg_tb10 clearfix">确定注单<span class="right padding_lr10" id="go_out"><img src="__IMG__/error.png" alt="" /></span> </h4>
		<div class="table_box bor_b">
			<table border="" cellspacing="" cellpadding="">
				<tr>
					<th>项目</th>
					<th>赔率</th>
					<th>金额</th>
					<th>删除</th>
				</tr>
			</table>
		</div>
		<p class="text-center padding_10">余额：<span>{$balance}</span></p>
		<div class="clearfix padding_10">
			<div class="left">
				注数：<span class="red1" id="total_zhu">5</span>
			</div>
			<div class="right">
				总额：<span class="red1" id="total_money">5.00</span>
			</div>
		</div>
		<div class="clearfix padding_10">
			<div class="right">
				<input class="bg_blue color_ff" type="button" onclick="betting()" value="确认下注" />
			</div>
		</div>
	</div>
</div>
<div class="spring_box4">
	<p class="color_ff text-center" style="line-height: 78px">
		本期已封盘，停止下注
	</p>
</div>

<div class="overlay"></div>
<script src="__JS__/jquery-1.7.1.min.js"></script>
<script src="__JS__/time.js" type="text/javascript" charset="utf-8"></script>
<script src="__JS__/index.js"></script>
<script src="__JS__/layer.js" ></script>
<script src="__JS__/rooms.js" ></script>
<script>
    $(function() {
        $(".table_box").css({"max-height":$(document).height()/3});
        //点击加注
        $('.my_td table td').click(function () {
            var number = $('.my_td table td.active').length;
            number = parseInt(number);
            $('#is_choose').html(number);
        });
    });
    //浮动层删除
    $(document).on("click",".dell",function() {
        $(this).parent().parent().remove();
        var zhu = parseInt($('#total_zhu').html());
        zhu = zhu-1;
        $('#total_zhu').html(zhu);
        var my_moneys = 0;
        $('.my_number').each(function () {
            var my_money =parseInt($(this).val());
            my_moneys = my_moneys+my_money;
        });
        $('#total_money').html(my_moneys);
    });
    //浮动层改变金额的值
    $(document).on("blur",".my_number",function() {
        var my_moneys = 0;
        $('.my_number').each(function () {
            var my_money =parseInt($(this).val());
            my_moneys = my_moneys+my_money;
        });
        $('#total_money').html(my_moneys);

    });

    //浮动层关闭
    $("#go_out").click(function(){
        out();
    });
    //清除所有active
    $("#cz").click(function(){
        $('.my_td table td.active').removeClass("active");
        $('#is_choose').html(0);
    });
    //浮动层关闭方法
    function out() {
        $(".overlay").hide();
        $(".spring_box3").fadeOut(200);
        $('.table_box table tr.tj').remove();
    }
	//排列组合的方法
	function choose(arr, size) {
		var allResult = [];
		(function (arr, size, result) {
			var arrLen = arr.length;
			if (size > arrLen) {
				return;
			}
			if (size == arrLen) {
				allResult.push([].concat(result, arr))
			} else {
				for (var i = 0 ; i < arrLen; i++) {
					var newResult = [].concat(result);
					newResult.push(arr[i]);

					if (size == 1) {
						allResult.push(newResult);
					} else {
						var newArr = [].concat(arr);
						newArr.splice(0, i + 1);
						arguments.callee(newArr, size - 1, newResult);
					}
				}
			}
		})(arr, size, []);
		return allResult;
	}
    //将数据添加到浮动层
    $("#ok").click(function(){
        var number =  $('.my_td table td.active').length;
        if(number<=0){
            my_error('请选择投注项');
            return false;
        }
        var money = $('#money').val();
        if(money=="" || money==0){
            my_error('请输入投注金额');
            return false;
        }
        var number_arr=[];
		var choose20 = [];
		var choose21 = [];
		var choose22 = [];
		var choose23 = [];
		var choose24 = [];
		var choose25 = [];
		var choose26 = [];
		var choose27 = [];
		var choose28 = [];
		var choose29 = [];
		var choose30 = [];
        $('.my_td table td.active').each(function () {
            var odds   = $(this).find('span').html();
            var number = $(this).find('i').html();
            var type   = $(this).find('input:eq(0)').val();
            var type_id = $(this).find('input:eq(1)').val();
            list = {};
            list['odds']     = odds;
            list['number']   = number;
            list['type']     = type;
            list['money']    = money;
            list['type_id']  = type_id;
			if(type_id=='20'){
				choose20.push(list);
			}else if(type_id==21){
				choose21.push(list);
			}else if(type_id==22){
				choose22.push(list);
			}else if(type_id==24){
				choose24.push(list);
			}else if(type_id==25){
				choose25.push(list);
			}else if(type_id==26){
				choose26.push(list);
			}else if(type_id==27){
				choose27.push(list);
			}else if(type_id==28){
				choose28.push(list);
			}else if(type_id==29){
				choose29.push(list);
			}else if(type_id==30){
				choose30.push(list);
			}else{
				number_arr.push(list);
			}

        });
		if(choose20.length !== 0){
			if(choose20.length<2){
				my_error('三全中至少选择三个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss20 = [];
			for(var k=0;k<choose20.length;k++){
				numberss20.push(choose20[k]['number']);
			}
			var numberss20_re = choose(numberss20,3);
			for(var g=0;g<numberss20_re.length;g++){
				list_d = {};
				list_d['odds']     = choose20[0]['odds'];
				list_d['number']   = numberss20_re[g][0]+','+numberss20_re[g][1]+','+numberss20_re[g][2];
				list_d['type']     = choose20[0]['type'];
				list_d['money']    = choose20[0]['money'];
				list_d['type_id']  = choose20[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose21.length !== 0){
			if(choose21.length<2){
				my_error('三中二至少选择三个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss21 = [];
			for(var k=0;k<choose21.length;k++){
				numberss21.push(choose21[k]['number']);
			}
			var numberss21_re = choose(numberss21,3);
			for(var g=0;g<numberss21_re.length;g++){
				list_d = {};
				list_d['odds']     = choose21[0]['odds'];
				list_d['number']   = numberss21_re[g][0]+','+numberss21_re[g][1]+','+numberss21_re[g][2];
				list_d['type']     = choose21[0]['type'];
				list_d['money']    = choose21[0]['money'];
				list_d['type_id']  = choose21[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose22.length !== 0){
			if(choose22.length<2){
				my_error('二全中至少选择两个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss22 = [];
			for(var k=0;k<choose22.length;k++){
				numberss22.push(choose22[k]['number']);
			}
			var numberss22_re = choose(numberss22,2);
			for(var g=0;g<numberss22_re.length;g++){
				list_d = {};
				list_d['odds']     = choose22[0]['odds'];
				list_d['number']   = numberss22_re[g][0]+','+numberss22_re[g][1];
				list_d['type']     = choose22[0]['type'];
				list_d['money']    = choose22[0]['money'];
				list_d['type_id']  = choose22[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose24.length !== 0){
			if(choose24.length<2){
				my_error('特串至少选择两个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss24 = [];
			for(var k=0;k<choose24.length;k++){
				numberss24.push(choose24[k]['number']);
			}
			var numberss24_re = choose(numberss24,2);
			for(var g=0;g<numberss24_re.length;g++){
				list_d = {};
				list_d['odds']     = choose24[0]['odds'];
				list_d['number']   = numberss24_re[g][0]+','+numberss24_re[g][1];
				list_d['type']     = choose24[0]['type'];
				list_d['money']    = choose24[0]['money'];
				list_d['type_id']  = choose24[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose25.length !== 0){
			if(choose25.length<4){
				my_error('四全中至少选择四个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss25 = [];
			for(var k=0;k<choose25.length;k++){
				numberss25.push(choose25[k]['number']);
			}
			var numberss25_re = choose(numberss25,4);
			for(var g=0;g<numberss25_re.length;g++){
				list_d = {};
				list_d['odds']     = choose25[0]['odds'];
				list_d['number']   = numberss25_re[g][0]+','+numberss25_re[g][1]+','+numberss25_re[g][2]+','+numberss25_re[g][3];
				list_d['type']     = choose25[0]['type'];
				list_d['money']    = choose25[0]['money'];
				list_d['type_id']  = choose25[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose26.length !== 0){
			if(choose26.length<2){
				my_error('二连肖至少选择两个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss26 = [];
			for(var k=0;k<choose26.length;k++){
				numberss26.push(choose26[k]['number']);
			}
			var numberss26_re = choose(numberss26,2);
			for(var g=0;g<numberss26_re.length;g++){
				list_d = {};
				list_d['odds']     = choose26[0]['odds'];
				list_d['number']   = numberss26_re[g][0]+','+numberss26_re[g][1];
				list_d['type']     = choose26[0]['type'];
				list_d['money']    = choose26[0]['money'];
				list_d['type_id']  = choose26[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose27.length !== 0){
			if(choose27.length<3){
				my_error('三连肖至少选择三个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss27 = [];
			for(var k=0;k<choose27.length;k++){
				numberss27.push(choose27[k]['number']);
			}
			var numberss27_re = choose(numberss27,3);
			for(var g=0;g<numberss27_re.length;g++){
				list_d = {};
				list_d['odds']     = choose27[0]['odds'];
				list_d['number']   = numberss27_re[g][0]+','+numberss27_re[g][1]+','+numberss27_re[g][2];
				list_d['type']     = choose27[0]['type'];
				list_d['money']    = choose27[0]['money'];
				list_d['type_id']  = choose27[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose28.length !== 0){
			if(choose28.length<4){
				my_error('四连肖至少选择四个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss28 = [];
			for(var k=0;k<choose28.length;k++){
				numberss28.push(choose28[k]['number']);
			}
			var numberss28_re = choose(numberss28,4);
			for(var g=0;g<numberss28_re.length;g++){
				list_d = {};
				list_d['odds']     = choose28[0]['odds'];
				list_d['number']   = numberss28_re[g][0]+','+numberss28_re[g][1]+','+numberss28_re[g][2]+','+numberss28_re[g][3];
				list_d['type']     = choose28[0]['type'];
				list_d['money']    = choose28[0]['money'];
				list_d['type_id']  = choose28[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose29.length !== 0){
			if(choose29.length<5){
				my_error('五连肖至少选择五个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss29 = [];
			for(var k=0;k<choose29.length;k++){
				numberss29.push(choose29[k]['number']);
			}
			var numberss29_re = choose(numberss29,5);
			for(var g=0;g<numberss29_re.length;g++){
				list_d = {};
				list_d['odds']     = choose29[0]['odds'];
				list_d['number']   = numberss29_re[g][0]+','+numberss29_re[g][1]+','+numberss29_re[g][2]+','+numberss29_re[g][3]+','+numberss29_re[g][4];
				list_d['type']     = choose29[0]['type'];
				list_d['money']    = choose29[0]['money'];
				list_d['type_id']  = choose29[0]['type_id'];
				number_arr.push(list_d);
			}
		}
		if(choose30.length !== 0){
			if(choose30.length<6){
				my_error('六连肖至少选择六个元素');
				return false;
			}
			if(choose20.length>10){
				my_error('最多选择10个元素');
				return false;
			}
			var numberss30 = [];
			for(var k=0;k<choose30.length;k++){
				numberss30.push(choose30[k]['number']);
			}
			var numberss30_re = choose(numberss30,6);
			for(var g=0;g<numberss30_re.length;g++){
				list_d = {};
				list_d['odds']     = choose30[0]['odds'];
				list_d['number']   = numberss30_re[g][0]+','+numberss30_re[g][1]+','+numberss30_re[g][2]+','+numberss30_re[g][3]+','+numberss30_re[g][4]+','+numberss30_re[g][5];
				list_d['type']     = choose30[0]['type'];
				list_d['money']    = choose30[0]['money'];
				list_d['type_id']  = choose30[0]['type_id'];
				number_arr.push(list_d);
			}
		}
        var str = "";
        for (var i=0;i<number_arr.length;i++) {
            str += "<tr class='tj'>"
                + "<td>"+number_arr[i].type+"@"+"<i>"+number_arr[i].number+"</i></td>"
                + "<td>"+number_arr[i].odds+"</td>"
                + "<td>"+"<input type='number' class='my_number'  value="+number_arr[i].money+">"
                + "</td>"
                + "<td><img class='dell' src='__IMG__/dell.png'/>"
                + "</td>"
                + "<td>"+"<input type='hidden'  value="+number_arr[i].type_id+">"
                + "</tr>"
        }
        $('.table_box table').append(str);
        var total_zhu =  number_arr.length;
        var total_money = total_zhu*money;
        $('#total_zhu').html(total_zhu);
        $('#total_money').html(total_money);
    });
    //下注
    function betting() {
        var stage = $('#next_stage').html();
        var cate = $('#cate').val();
        var number_arr=[];
        $('.table_box table tr.tj').each(function(){
            var money  =  $(this).find('input:eq(0)').val();
            var type   =  $(this).find('input:eq(1)').val();
            var number =  $(this).find('i').html();
            list = {};
            list['type']   = type;
            list['number'] = number;
            list['money']  = money;
            number_arr.push(list);
        });
        if(number_arr.length<=0){
			my_error('投注元素不能为空！');
			return false;
		}
        var list1 = JSON.stringify(number_arr);
        $.ajax({
            type: "post",
            url: "{:url('game/betting')}",
            data: {'cate':cate,'stage':stage,'hall':1,'list':list1},
            dataType: "json",
            async: false,
            success: function(data) {
                var ret   = data.ret;
                var info  = data.msg;
                var blance = data.data.money;
                if(ret=='200'){
                    $('#balance').html(blance);
                    out();
                    $('.my_td table td.active').removeClass("active");
                    my_error(info);
                }else{
                    my_error(info);
                }
            }
        });

    }

</script>
</body>
</html>
